import axios from 'axios'
const { getCookie } = require('~/utils')

export default ({ store, route, req }) => {
  if (process.server || /\./g.test(route.path)) { return }

  axios.post('/api/visit', {
    userAgent: navigator.userAgent,
    visible: store.state.isAppVisible,
    markId: getCookie('markId'),
    offset: new Date().getTimezoneOffset(),
    refer: document.referrer,
    alive: store.state.isAppAlive,
    date: new Date().toLocaleString(),
    path: route.path
  })
  store.commit('SET_ALIVE')
}
